<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="职业领域" prop="jobRealm">
        <el-input
          v-model="queryParams.jobRealm"
          placeholder="请输入职业领域"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职业名称" prop="jobName">
        <el-input
          v-model="queryParams.jobName"
          placeholder="请输入职业名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职业路径" prop="jobPath">
        <el-input
          v-model="queryParams.jobPath"
          placeholder="请输入职业路径"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:CompassJobInfo:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <importData
          v-hasPermi="['system:CompassJobInfo:edit']"
          title="职业"
          action="CompassJobInfo"
          @success="getList"
        >
        </importData>
      </el-col>
      <el-col :span="1.5">
        <importData
          v-hasPermi="['system:CompassJobInfo:edit']"
          title="职业相关专业"
          action="specialtyJobRelation"
        >
        </importData>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:CompassJobInfo:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:CompassJobInfo:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="CompassJobInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="职业领域" align="center" prop="jobRealm"/>
      <el-table-column label="职业名称(中文)" align="center" prop="jobName"/>
      <el-table-column label="职业路径" align="center" prop="jobPath"/>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:CompassJobInfo:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:CompassJobInfo:remove']"
          >删除
          </el-button>
          <!--<el-button
            @click="showZhuanye(scope.row)"
            size="mini"
            type="text"
            icon="el-icon-share"
          >相关专业
          </el-button>-->
          <router-link :to="'/job_zhuanye/' + scope.row.jobName" class="link-type">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-share"
            >相关专业
            </el-button>
          </router-link>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改职业信息表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="750px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="85px" size="small">
        <el-row>
          <el-col :span="12">
            <el-form-item label="职业名称" prop="jobName">
              <el-input v-model="form.jobName" placeholder="请输入职业名称(中文)"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="职业领域" prop="jobRealm">
              <el-input v-model="form.jobRealm" placeholder="请输入职业领域"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="职业路径" prop="jobPath">
              <el-input v-model="form.jobPath" placeholder="请输入职业路径"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="顶部banner" prop="fileType"  label-width="100px">
              <el-radio-group v-model="form.fileType">
                <el-radio label="video">视频</el-radio>
                <el-radio label="image">图片</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="文件上传" prop="fileUrl" label-width="90px">
              <el-radio-group v-model="video_fun" v-if="form.fileType == 'video'">
                <el-radio label="upload">本地上传</el-radio>
                <el-radio label="url">输入视频地址</el-radio>
              </el-radio-group>
              <Upload v-model="form.fileUrl" v-if="form.fileType == 'image'"/>
              <Upload v-model="form.fileUrl" type="video" v-if="form.fileType == 'video' && video_fun =='upload'"/>
              <el-input v-model="form.fileUrl" placeholder="请输入视频地址" v-if="form.fileType == 'video' && video_fun =='url'"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="知识背景" prop="inforBack">
          <el-input v-model="form.inforBack" :autosize="{minRows: 3}" type="textarea" placeholder="请输入知识背景"/>
        </el-form-item>
        <el-form-item label="薪酬待遇" prop="salaryDesc">
          <el-input v-model="form.salaryDesc" :autosize="{minRows: 3}" type="textarea" placeholder="请输入薪酬待遇"/>
        </el-form-item>
        <el-form-item label="发展前景" prop="developProspect">
          <el-input v-model="form.developProspect" :autosize="{minRows: 3}" type="textarea" placeholder="请输入发展前景"/>
        </el-form-item>
        <el-form-item label="职业定义" prop="jobDefinition">
          <el-input v-model="form.jobDefinition" :autosize="{minRows: 3}" type="textarea" placeholder="请输入职业定义"/>
        </el-form-item>
        <el-form-item label="职业解析" prop="jobAnalyze">
          <el-input v-model="form.jobAnalyze" :autosize="{minRows: 3}" type="textarea" placeholder="请输入职业解析"/>
        </el-form-item>
        <el-form-item label="职业技能" prop="jobKill">
          <el-input v-model="form.jobKill" :autosize="{minRows: 3}" type="textarea" placeholder="请输入职业技能"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align: center">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!--相关专业-->
    <el-dialog
      :title="`${title_pre}相关专业`"
      :visible.sync="dialogVisible"
      width="500px">
      <el-table
        :data="specialtyJobRelationList"
        style="width: 100%">
        <el-table-column
          type="index"
          width="50">
        </el-table-column>
        <el-table-column
          prop="jobName"
          label="职业名称">
        </el-table-column>
        <el-table-column
          prop="specialtyName"
          label="专业名称">
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer" style="text-align: center">
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import {
    listCompassJobInfo,
    getCompassJobInfo,
    delCompassJobInfo,
    addCompassJobInfo,
    updateCompassJobInfo,
    exportCompassJobInfo
  } from "@/api/system/CompassJobInfo";
  import Upload from '@/components/Upload/index'

  import dictMixins from "@/views/mixins/dictMixins";

  export default {
    name: "CompassJobInfo",
    mixins: [dictMixins],
    components: {Upload},
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 职业信息表表格数据
        CompassJobInfoList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          jobRealm: null,
          jobName: null,
          jobPath: null
        },
        // 表单参数
        form: {fileType: 'image'},
        // 表单校验
        rules: {
          jobName: [{ required: true, message: "请输入职业名称" }],
          jobRealm: [{ required: true, message: "请输入职业领域" }],
          jobPath: [{ required: true, message: "请输入职业路径"}],
          fileType: [{ required: true, message: "请选择顶部banner类型"}],
        },

        dialogVisible: false,
        title_pre: '',
        specialtyJobRelationList:[],
        video_fun: 'upload'
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询职业信息表列表 */
      getList() {
        this.loading = true;
        listCompassJobInfo(this.queryParams).then(response => {
          this.CompassJobInfoList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          createTime: null,
          inforBack: null,
          jobAnalyze: null,
          jobRealm: null,
          jobKill: null,
          salaryDesc: null,
          jobName: null,
          id: null,
          updateTime: null,
          developProspect: null,
          jobDefinition: null,
          jobPath: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.$set(this.form, 'fileType', 'image')
        this.open = true;
        this.title = "添加职业信息表";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getCompassJobInfo(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改职业信息表";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateCompassJobInfo(this.form).then(response => {
                if (response.code === 200) {
                  this.msgSuccess("修改成功");
                  this.open = false;
                  this.getList();
                }
              });
            } else {
              addCompassJobInfo(this.form).then(response => {
                if (response.code === 200) {
                  this.msgSuccess("新增成功");
                  this.open = false;
                  this.getList();
                }
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$confirm('是否确认删除职业信息表编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function () {
          return delCompassJobInfo(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function () {
        });
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有职业信息表数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function () {
          return exportCompassJobInfo(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function () {
        });
      },

      // 导入
      handleUpload() {

      },

      showZhuanye(row) {
        /*console.log(row)

        return
        this.$router.push({
          name: "job_zhuanye/" + row.jobName,
          query: {
            id: row && row.id,
            detail: detail
          }
        });*/
        this.title_pre = row.jobName
        getCompassJobInfo(row.id).then(response => {
          this.specialtyJobRelationList = response.data.specialtyJobRelationList
          this.dialogVisible = true
        });
      }
    }
  };
</script>
